package com.itheima.wallet.service;


import com.itheima.wallet.api.AccountServiceApi;
import com.itheima.wallet.mapper.AccountMapper;
import com.itheima.wallet.user.api.UserLoginServiceApi;
import com.itheima.wallet.user.pojos.Account;
import com.itheima.wallet.user.pojos.User;
import com.itheima.wallet.vo.PageResult;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service(version = "1.0.0")
public class AccountService implements AccountServiceApi {
    @Reference(version = "1.0.0")
    private UserLoginServiceApi userLoginService;
    @Autowired
    private AccountMapper accountMapper;


    @Override
    public PageResult queryAccountInfo(Long accountId, String token) {
        try {
            //校验token
            User user = this.userLoginService.checkTokenService(token);
            if(null == user){
                return null;
            }

            //判断参数
            if(null==accountId){
                return null;
            }

            //都没有问题就查询
            Account account = this.accountMapper.selectById(accountId);
            if(account==null){
                return null;
            }

            PageResult pageResult = new PageResult();
            List<Account> result = new ArrayList<>();
            result.add(account);
            pageResult.setRecords(result);
            return pageResult;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
